package com.example.mall.web.controller;

import com.example.mall.domain.UserPersonalizedRecommendations;
import com.example.mall.dto.UserPersonalizedRecommendationsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.UserPersonalizedRecommendationsQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IUserPersonalizedRecommendationsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/userPersonalizedRecommendations")
public class UserPersonalizedRecommendationsController {

    @Autowired
    public IUserPersonalizedRecommendationsService userPersonalizedRecommendationsService;

    /**
     * 分页查询用户个性化推荐表信息
     * @param userPersonalizedRecommendationsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询用户个性化推荐表信息",notes = "分页查询用户个性化推荐表信息",httpMethod = "GET")
    public JSONResult queryPage(UserPersonalizedRecommendationsQuery userPersonalizedRecommendationsQuery){
        PageDTO<UserPersonalizedRecommendationsDto> userPersonalizedRecommendationsDtoPageDTO = userPersonalizedRecommendationsService.queryPage(userPersonalizedRecommendationsQuery);
        return JSONResult.success("查询成功",userPersonalizedRecommendationsDtoPageDTO);
    }

    /**
     * 根据id查询用户个性化推荐表信息
     * @param recommendId
     * @return
     */
    @GetMapping("query/{recommendId}")
    @ApiOperation(value = "根据id查询用户个性化推荐表信息",notes = "根据id查询用户个性化推荐表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("recommendId")Long recommendId){
        //1.根据id查询用户信息
        if (recommendId == null){
            throw new GlobalCustomerException(ErrorEnumCode.USER_PERSONALIZED_RECOMMENDID_NOT_ID);
        }
        UserPersonalizedRecommendations userPersonalizedRecommendations = userPersonalizedRecommendationsService.getById(recommendId);
        return JSONResult.success("查询成功",userPersonalizedRecommendations);
    }

    /**
     * 根据id查询用户个性化推荐表信息
     * @param recommendId
     * @return
     */
    @GetMapping("queryUserPersonalizedRecommendationsById/{recommendId}")
    @ApiOperation(value = "根据id查询用户个性化推荐表信息",notes = "根据id查询用户个性化推荐表信息",httpMethod = "GET")
    public JSONResult queryUserPersonalizedRecommendationsById(@PathVariable("recommendId")Long recommendId){
        //1.根据id查询用户信息
        if (recommendId == null){
            throw new GlobalCustomerException(ErrorEnumCode.USER_PERSONALIZED_RECOMMENDID_NOT_ID);
        }
        UserPersonalizedRecommendations userPersonalizedRecommendations = userPersonalizedRecommendationsService.queryUserPersonalizedRecommendationsById(recommendId);
        return JSONResult.success("查询成功",userPersonalizedRecommendations);
    }

    /**
     * 查询全部用户个性化推荐表信息
     * @param
     * @return
     */
    @GetMapping("queryUserPersonalizedRecommendationsList")
    @ApiOperation(value = "查询全部用户个性化推荐表信息",notes = "查询全部用户个性化推荐表信息",httpMethod = "GET")
    public JSONResult queryUserPersonalizedRecommendationsList(){
        List<UserPersonalizedRecommendations> userPersonalizedRecommendations = userPersonalizedRecommendationsService.queryUserPersonalizedRecommendationsList();
        return JSONResult.success("查询成功",userPersonalizedRecommendations);
    }

    /**
     * 新增用户个性化推荐表
     * @param userPersonalizedRecommendationsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增用户个性化推荐表",notes = "新增用户个性化推荐表",httpMethod = "POST")
    public JSONResult insert(@RequestBody UserPersonalizedRecommendationsDto userPersonalizedRecommendationsDto){
        userPersonalizedRecommendationsService.insert(userPersonalizedRecommendationsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改用户个性化推荐表信息
     * @param userPersonalizedRecommendationsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改用户个性化推荐表信息",notes = "修改用户个性化推荐表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody UserPersonalizedRecommendationsDto userPersonalizedRecommendationsDto){
        userPersonalizedRecommendationsService.update(userPersonalizedRecommendationsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除用户个性化推荐表信息
     * @param recommendId
     * @return
     */
    @PostMapping("delete/{recommendId}")
    @ApiOperation(value = "删除用户个性化推荐表信息",notes = "删除用户个性化推荐表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("recommendId") Long recommendId) {
        userPersonalizedRecommendationsService.delete(recommendId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除用户个性化推荐表信息
     * @param recommendIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除用户个性化推荐表信息",notes = "批量删除用户个性化推荐表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> recommendIds) {
        userPersonalizedRecommendationsService.deleteBatch(recommendIds);
        return JSONResult.success("批量删除成功");
    }
}
